package kin.system.util;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;




import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.Thumbnails.Builder;


public class PhotoUtil {
	public static String convert(int widthSize,int heightSize,String fileName,String extion)throws IOException{
		Builder<File> bf=null;
		File f=new File(fileName); 
		BufferedImage image = ImageIO.read(f);
		if(heightSize<image.getHeight()&&widthSize<image.getWidth()){
		 bf=Thumbnails.of(f).size(widthSize, heightSize);
		}else{
			return null;
		}
	if(extion.equals("png")){
		bf.outputFormat("png");
	}else{
		bf.outputFormat("jpeg");
	} 
	//f:\photo\48e2ca7a721d6
	String path = fileName.substring(0,fileName.lastIndexOf('.') ).toLowerCase();
	String ext=fileName.substring(fileName.lastIndexOf(".")+1,fileName.length()).toLowerCase();
	//System.out.println(ext);
	File small=new File(path+"_small");
			        bf.outputQuality(1f).toFile(small);
			       String name= small.getName();
			       
			 return name+"."+ext;       

	
	}
}
